package io.github.lee.app.unsplash.ui.detail.photo

import android.content.Context
import android.content.Intent
import androidx.core.os.bundleOf
import androidx.databinding.ViewDataBinding
import dagger.hilt.android.AndroidEntryPoint
import io.github.lee.app.unsplash.repository.domain.Photo
import io.github.lee.core.ui.BaseActivity
import io.github.lee.core.util.getBundleParcelable
import io.github.lee.core.vm.BaseViewModel

@AndroidEntryPoint
class PhotoDetailActivity : BaseActivity<ViewDataBinding, BaseViewModel>() {

    companion object {
        private const val KEY_PHOTO = "PHOTO"

        @JvmStatic
        fun start(context: Context, photo: Photo) {

            val starter = Intent(context, PhotoDetailActivity::class.java)
                .putExtras(
                    bundleOf(
                        KEY_PHOTO to photo
                    )
                )
            context.startActivity(starter)
        }
    }
    //===Desc:===============================================================================


    override fun onSetViewData() {
        super.onSetViewData()

        val photo = getBundleParcelable(KEY_PHOTO, Photo::class.java)
        if (null == photo) {
            showError()
            return
        }
        replaceFragment(PhotoDetailFragment.newInstance(photo))


    }
}